package iflytek;

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int n;
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        ArrayList<Integer> a=new ArrayList<Integer>();

        for (int i = 0; i < n; i++)
            a.add(sc.nextInt());

        int cnt = 0;
        while (true) {
        ArrayList<Integer> t = solve(a);
        if (t.size() == a.size()) break;
        a = t;
        cnt++;
        }
        System.out.println(cnt);
    }
    public static ArrayList<Integer> solve(ArrayList<Integer> a) {
        ArrayList<Integer> res=new ArrayList<Integer>();
        int i = 0, n = a.size();
        while (i < n) {
        int j = i + 1;
        while (j < n && a.get(j) < a.get(j-1)) j++;
        res.add(a.get(i));
        i = j;
        }
        return res;
        }
}
